package me.jiatao.paging2

import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager.VERTICAL
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.VERTICAL
import me.jiatao.paging2.adapter.ProjectAdapter
import me.jiatao.paging2.viewmodel.ProjectViewModel

class MainActivity : AppCompatActivity() {

    private val viewModel by viewModels<ProjectViewModel>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val recyclerView: RecyclerView = findViewById(R.id.recyclerView)
        val projectAdapter = ProjectAdapter()

        recyclerView.apply {
            layoutManager = LinearLayoutManager(this@MainActivity)
            adapter = projectAdapter
        }


        viewModel.getProjectViewModel().observe(this, {
            println("viewModel observe----------> ${Thread.currentThread().name}")
            projectAdapter.submitList(it)
        })

    }


    fun startRequest(view: View) {


    }
}